package com.hjwoo.app.adpter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hjwoo.app.R;

public class DiscoverGVAdapter extends BaseAdapter
{

    Context    context;
    // 定义一个视图容器
    ViewHolder holder;
    // 定义一个商品集合
//	List<DiscoverMenuObject> myMenuLS;
    // 用来导入布局
    private LayoutInflater inflater = null;
    private int[]    imageViewIds;
    private String[] menuStrs;

    //	public DiscoverGVAdapter(Context context) {
//		super();
//		this.context = context;
//		inflater = LayoutInflater.from(context);
//		// 创建bitmap
//	}
    public DiscoverGVAdapter(Context context, int[] imageViewIds, String[] menuStrs)
    {
        super();
        this.context = context;
//		this.myMenuLS = myMenuLS;
        this.imageViewIds = imageViewIds;
        this.menuStrs = menuStrs;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount()
    {
//		return 9;
        return menuStrs.length;
    }

    @Override
    public Object getItem(int arg0)
    {
        return arg0;
    }

    @Override
    public long getItemId(int arg0)
    {
        return arg0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        // 定义一个视图容器
        holder = null;
        if (convertView == null)
        {
            // 获取ViewHolder对象
            holder = new ViewHolder();
            // 导入布局并赋值给convertview
            convertView = inflater.inflate(R.layout.item_discover_gv, null);
            holder.item_discover_iv = (ImageView) convertView
                .findViewById(R.id.item_discover_iv);
            holder.item_discover_tv = (TextView) convertView
                .findViewById(R.id.item_discover_tv);

            convertView.setTag(holder);
        }
        else
        {
            // 取出holder
            holder = (ViewHolder) convertView.getTag();
        }

        holder.item_discover_iv.setImageResource(imageViewIds[position]);
        holder.item_discover_tv.setText(menuStrs[position]);

        return convertView;
    }

    /**
     * 视图容器类
     *
     * @author kz
     */
    public static class ViewHolder
    {
        public ImageView item_discover_iv;
        public TextView  item_discover_tv;
    }

}
